package android.slc.module.component.dict.entity;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/12/13 下午 2:48
 */
public class TreeDictWrap {
    private List<? extends ITreeDict<?>> sysDictList;
    private String[] dictLabelArray;

    public TreeDictWrap() {

    }

    public TreeDictWrap(List<? extends ITreeDict<?>> sysDictList) {
        setSysDictList(sysDictList);
    }

    public List<? extends ITreeDict<?>> getSysDictList() {
        return sysDictList;
    }

    public void setSysDictList(List<? extends ITreeDict<?>> sysDictList) {
        this.sysDictList = sysDictList;
        dictLabelArray = dictList2LabelArray(sysDictList);
    }

    public String[] getDictLabelArray() {
        return dictLabelArray;
    }

    public void setDictLabelArray(String[] dictLabelArray) {
        this.dictLabelArray = dictLabelArray;
    }

    public static <T extends ITreeDict<?>> String[] dictList2LabelArray(List<T> dictList) {
        if (CollectionUtils.isEmpty(dictList)) {
            return new String[0];
        }
        final String[] labelArray = new String[dictList.size()];
        CollectionUtil.forEach(dictList, new CollUtil.Consumer<T>() {
            @Override
            public void accept(T item, int index) {
                labelArray[index] = StringUtils.isEmpty(item.getTdDictLabel()) ? " " : item.getTdDictLabel();
            }
        });
        return labelArray;
    }
}
